﻿using System;
using System.Reflection;
using UnityEngine;

// Token: 0x02000004 RID: 4
public class BustSoftEx
{
	// Token: 0x0600000A RID: 10 RVA: 0x00002C90 File Offset: 0x00000E90
	public static void ReCalcEx(BustSoft that, int[] changePtn)
	{
		CharFemale charFemale = BustSoftEx.f_female.GetValue(that) as CharFemale;
		if (BustSoftEx.f_female.GetValue(that) == null)
		{
			return;
		}
		CharFileInfoCustomFemale charFileInfoCustomFemale = BustSoftEx.f_customInfo.GetValue(that) as CharFileInfoCustomFemale;
		if (charFileInfoCustomFemale == null)
		{
			return;
		}
		if (changePtn.Length == 0)
		{
			return;
		}
		float rate = Mathf.Clamp(charFileInfoCustomFemale.bustSoftness, 0f, float.MaxValue) * Mathf.Clamp(charFileInfoCustomFemale.shapeValueBody[1], 0f, float.MaxValue) + 0.01f;
		float[] vals = BustSoftEx.f_bustStiffness.GetValue(that) as float[];
		float[] vals2 = BustSoftEx.f_bustElasticity.GetValue(that) as float[];
		float[] vals3 = BustSoftEx.f_bustDamping.GetValue(that) as float[];
		float stiffness = BustSoftEx.TreeLerpEx(vals, rate);
		float elasticity = BustSoftEx.TreeLerpEx(vals2, rate);
		float damping = BustSoftEx.TreeLerpEx(vals3, rate);
		DynamicBone_Ver02[] array = new DynamicBone_Ver02[]
		{
			charFemale.getDynamicBone(CharFemaleBody.DynamicBoneKind.BreastL),
			charFemale.getDynamicBone(CharFemaleBody.DynamicBoneKind.BreastR)
		};
		foreach (int ptn in changePtn)
		{
			foreach (DynamicBone_Ver02 dynamicBone_Ver in array)
			{
				if (dynamicBone_Ver != null)
				{
					dynamicBone_Ver.setSoftParams(ptn, -1, damping, elasticity, stiffness, true);
				}
			}
		}
	}

	// Token: 0x0600000B RID: 11 RVA: 0x00002DC8 File Offset: 0x00000FC8
	private static float TreeLerpEx(float[] vals, float rate)
	{
		if (rate < 0f)
		{
			return vals[0] + (vals[1] - vals[0]) * rate * 2f;
		}
		if (rate > 1f)
		{
			return vals[1] + (vals[2] - vals[1]) * (rate - 0.5f) * 2f;
		}
		if (rate < 0.5f)
		{
			return Mathf.Lerp(vals[0], vals[1], rate * 2f);
		}
		return Mathf.Lerp(vals[1], vals[2], (rate - 0.5f) * 2f);
	}

	// Token: 0x04000005 RID: 5
	private static FieldInfo f_female = typeof(BustSoft).GetField("female", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField);

	// Token: 0x04000006 RID: 6
	private static FieldInfo f_customInfo = typeof(BustSoft).GetField("customInfo", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField);

	// Token: 0x04000007 RID: 7
	private static FieldInfo f_bustStiffness = typeof(BustSoft).GetField("bustStiffness", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField);

	// Token: 0x04000008 RID: 8
	private static FieldInfo f_bustElasticity = typeof(BustSoft).GetField("bustElasticity", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField);

	// Token: 0x04000009 RID: 9
	private static FieldInfo f_bustDamping = typeof(BustSoft).GetField("bustDamping", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField);
}
